<?php

$user = $facebook->getUser();

if ($user) 
{
  try 
  {
    $user_profile = $facebook->api('/me');
  } 
  catch (FacebookApiException $e) 
  {
    error_log($e);
    $user = null;
	echo "aaa**";
  }
}

if ($user) 
{
  $logoutUrl = $facebook->getLogoutUrl();
} 
else 
{
	$params = array('scope' => 'user_photos,friends_photos' );
	$loginUrl = $facebook->getLoginUrl($params);
}


?>
<!doctype html>
<html>
  <head>
    <title>guaripolo connect fb php sdk</title>
	<script type="text/javascript" src="<?php echo base_url();?>assets/js/jquery-1.7.2.min.js"></script>
	<script type="text/javascript" src="<?php echo base_url();?>assets/js/jquery-ui-1.8.20.custom.min.js"></script>

	<link type="text/css" href="<?php echo base_url();?>assets/css/jquery-ui-1.8.20.custom.css" rel="stylesheet" />
	<script>
	$(document).ready(function(){
	$("#album").dialog({ autoOpen: false ,width:700,height:500, modal: true ,open: function(event, ui) { 
		//hide close button.
		$(this).parent().children().children('.ui-dialog-titlebar-close').hide();
		}});
	$("#descarga1").dialog({ autoOpen: false ,width:700,height:500, modal: true ,open: function(event, ui) { 
		//hide close button.
		$(this).parent().children().children('.ui-dialog-titlebar-close').hide();
		}});
	$("#albumcomplete").dialog({ autoOpen: false ,width:700,height:500, modal: true ,open: function(event, ui) { 
		//hide close button.
		$(this).parent().children().children('.ui-dialog-titlebar-close').hide();
		}});
	$("#imgbig").dialog({ autoOpen: false ,width:730,height:730, modal: true ,open: function(event, ui) { 
		//hide close button.
		$(this).parent().children().children('.ui-dialog-titlebar-close').hide();
		}});

	})
	function imageBig(src)
	{
		$("#imgbig").dialog('close');
		$("#imgbig").dialog('open');
		$("#imgbig").html( "<img src="+src+"/>" + "<br><input type='button' onclick =fuclose('imgbig') value ='Close'/>");
	}
	function albumComplete(idu,ida)
	{
		$("#albumcomplete").dialog('close');
		$("#albumcomplete").dialog('open');
		$("#albumcomplete").html( "Cargando album, esto puede tardar... <img src='<?php base_url()?>assets/images/loader.gif'/>" );
		
		var request = $.ajax({
		  url: "<?php echo base_url()?>album/ajax3",
		  type: "POST",
		  data: { uid: idu,aid: ida},
		  cache: false
		});

		request.done(function(html) {
		  $("#albumcomplete").html( html + "<br><input type='button' onclick =fuclose('albumComplete') value ='Close'/>");
		});

		request.fail(function(jqXHR, textStatus) {
		  alert( "Request failed: " + textStatus );
		});
	}

	function fuclose(id)
	{

			$('#'+id).dialog('close');


	}
	function album(id)
	{
	$("#album").dialog('close');
	$("#album").dialog('open');
	$("#album").html( "Cargando albums, esto puede tardar... <img src='<?php base_url()?>assets/images/loader.gif'/>" );

	var request = $.ajax({
		  url: "<?php echo base_url()?>album/ajax1",
		  type: "POST",
		  data: { uid: id},
		  cache: false
		});

		request.done(function(html) {
		  $("#album").html( html + "<br><input type='button' onclick =fuclose('album') value ='Close'/>");
		});

		request.fail(function(jqXHR, textStatus) {
		  alert( "Request failed: " + textStatus );
		});
	}
	
	
	function descargarAlbum(idu,ida)
	{
	$("#descarga1").dialog('close');
	$("#descarga1").dialog('open');
	$("#descarga1").html( "Creando archivo zip, esto puede tardar... <img src='<?php base_url()?>assets/images/loader.gif'/>" );

	var request = $.ajax({
		  url: "<?php echo base_url()?>album/ajax2",
		  type: "POST",
		  data: { uid: idu,aid: ida},
		  cache: false
		});

		request.done(function(html) {
		  $("#descarga1").html( html + "<br><input type='button' onclick =fuclose('descarga1') value ='Close'/>" );
		});

		request.fail(function(jqXHR, textStatus) {
		  alert( "Request failed: " + textStatus );
		});

	}
	
	</script>
	<style>
		.enlace:hover
		{
			border:2px solid red;
			cursor:pointer
		}


	</style>
  </head>
  <body>
  <div id="container">
	prueba albumes:
  <div id="fb-root"></div>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>

    <script>
    var uiSize = FB.UIServer.Methods["fbml.dialog"].size;
    FB.UIServer.Methods["fbml.dialog"].size = {width:720, height:555};
    var dialog = {
    method: 'fbml.dialog',
    width: 700,
    height: 500,
    display: 'dialog',
    fbml: '<fb:request-form action="http://apps.facebook.com/nombredetuapp" method="post" target="_self" invite="true" type="Contest" content="Come and Join this contest!"> <fb:multi-friend-selector showborder="false" max="35" import_external_friends="false" email_invite="true" cols="5" actiontext="Frase que invita a tus amigos a compartir" bypass="cancel" /></fb:request-form>'
  };
    FB.ui(dialog,function(response) {
        alert(parent);
    });
</script>
	
    <?php if ($user): ?>
		<a href="<?php echo $logoutUrl; ?>">Logout</a>
	<?php else: ?>
		<a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
    <?php endif ?>
    <?php if ($user):?>
		<strong><em>conectado<br><br></strong>
		
	<?php 
	
		
		
		

		$params1=array( 'method' => 'fql.query','query' => "SELECT uid,name,pic from user where uid in (SELECT uid2 FROM friend WHERE uid1 = me())" );
		$r1 = $facebook->api($params1);
		
		echo "<div class='enlace' onclick = 'album(".$user_profile['id'].")'><h2>".$user_profile['name']."</h2></div><br>";
		
/*		echo "<pre>";
		print_r($user_profile);
		echo "</pre>";*/
		foreach($r1 as $u)
		{
			echo "<div class='enlace' onclick = 'album(".$u['uid'].")'><img  src=".$u['pic']."/>".$u['name']." ".$u['uid']."</div><br>";
			
		}
	
	

		?>
    <?php else: ?>
		<strong><em>no conectado</strong>
    <?php endif ?>

	<div class="dia" id="album"></div>
	<div class="dia" id="descarga1"></div>
	<div class="dia" id="albumcomplete"></div>
	<div class="dia" id="imgbig"></div>
	

	
	</div>
  </body>
</html>
